define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'bootstrap-table-jumpto'], function ($, undefined, Backend, Table, Form,showJumpto) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'ad/ads/index' + location.search,
                    add_url: 'ad/ads/add' + location.search,
                    edit_url: 'ad/ads/edit' + location.search,
                    del_url: 'ad/ads/del' + location.search,
                    multi_url: 'ad/ads/multi',
                    table: 'self_ad_ads',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                sortOrder:'desc',
                pageList: [10, 20, 50],
                showExport: false,
                showJumpto: true,
                searchFormVisible: true,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'name', title: '商家名称', operate: 'like'},
                        {field: 'keyword', title: '关键字', operate: 'like'},
                        {field: 'title', title: __('Title'), operate: 'like'},
                        {field: 'src', title: __('Src'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'linkurl', title: __('Linkurl'), formatter: Table.api.formatter.url, operate: false},
                        {field: 'target', title: __('Target'), searchList: {"_self":__('_self'),"_blank":__('_blank')}, formatter: Table.api.formatter.normal},
                        {field: 'switch', title: '是否有效', searchList: {'0': '无效',"1":'有效'}, formatter: Table.api.formatter.toggle},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime,operate: false},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,

                            buttons: [
                                {
                                    name: 'click-count',
                                    text: '点击量',
                                    classname: 'btn btn-xs btn-warning btn-dialog',
                                    icon: 'fa fa-gg-circle',
                                    extend: 'data-area=\'["100%", "100%"]\'',
                                    url: 'ad/click/index?ad_id={ids}'
                                }
                            ],

                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});